package com.zzq.base.awesome.utils;

import com.zzq.base.awesome.entity.CommonData;
import com.zzq.base.awesome.entity.SingleObject;
import org.slf4j.Logger;

import java.io.File;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;

/**
 * @author 赵自强
 */
public class SystemUtils {

	public static boolean isWindows() {
		return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS");
	}

	public static String getUUID(){
		return UUID.randomUUID().toString().replace("-", "");
	}

	public static boolean isNotListEmpty(List list) {
		return !isListEmpty(list);
	}

	public static boolean isListEmpty(List list) {
		return (list == null || list.size() == 0);
	}

	//方法1：length为产生的位数
	public static String getRandomString(int length){
		//定义一个字符串（A-Z，a-z，0-9）即62位；
		String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
		//由Random生成随机数
		Random random=new Random();
		StringBuffer sb=new StringBuffer();
		//长度为几就循环几次
		for(int i=0; i<length; ++i){
			//产生0-61的数字
			int number=random.nextInt(62);
			//将产生的数字通过length次承载到sb中
			sb.append(str.charAt(number));
		}
		//将承载的字符转换成字符串
		return sb.toString();
	}

	public static void initFile(Logger log) {
		if (isWindows()) {
			SingleObject.filePath = CommonData.WINDOWSFILEPATH;
			SingleObject.avatarPath = SingleObject.filePath + "avatar/";
			File file = new File(SingleObject.filePath);
			if (!file.exists()) {
				log.info("初始化文件目录");
				file.mkdirs();
				new File(SingleObject.avatarPath).mkdir();
			}else {
				File file1 = new File(SingleObject.avatarPath);
				if (!file1.exists()) {
					log.info("初始化头像存储目录");
					file1.mkdir();
				}
			}
		}
	}
}
